package com.paipai.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayDeadSaleMqConfig {
    //死信部分
    //死信交换机
    @Bean
    public DirectExchange deadLetterExchange() {
        return new DirectExchange("deadLetterExchange");
    }

    //死信队列
    @Bean
    public Queue deadLetterQueue() {
        return new Queue("deadLetterQueue");
    }

    //死信绑定
    @Bean
    public Binding deadLetterBind() {
        return BindingBuilder.bind(deadLetterQueue()).to(deadLetterExchange()).with("deadLetterRoutingKey");
    }

    //普通队列 绑定死信交换机的路由key 以及ttl 用到QueueBuilder
    //设定时间一天
    @Bean
    public Queue normalQueue() {
        return QueueBuilder.durable("normalQueue").deadLetterExchange("deadLetterExchange").deadLetterRoutingKey("deadLetterRoutingKey").ttl(60 * 1000 ).build();
    }

    //普通交换机
    @Bean
    public DirectExchange normalExchange() {
        return new DirectExchange("normalExchange");
    }

    //普通交换机和队列的绑定(生产者指定的路由key)
    @Bean
    public Binding normalBinding() {
        return BindingBuilder.bind(normalQueue()).to(normalExchange()).with("normalRoutingKey");
    }

}
